<?php
	//TODO: add isset checks

	$x = $_GET['x'];
	$y = $_GET['y'];
	$txt = $_GET['txt'];
	$eventID = 1; //<-- this will be saved in a session in full release. TODO: remove test 
	
?>

<html>
<head>
	<script>
		function save() {
			//get header + content:
			var html = document.body.innerHTML;
			var buttonText = "<?php echo $txt?>";
			var x = <?php echo $x?>;
			var y = <?php echo $y?>;
			var eid = <?php echo $eventID; ?>
			
			var toSend = {"html":html, "buttonText":buttonText, "buttonX":x, "buttonY":y, "eventID":eid};
			var toSend = JSON.stringify(toSend);
			
			//TODO: save cell in db (using xmlhttp)
			var xmlhttp;
			if (window.XMLHttpRequest) {
				xmlhttp=new XMLHttpRequest();
			}
			else {
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			
			xmlhttp.open("POST", "saveCellScript.php", true);
			xmlhttp.setRequestHeader("Content-type", "application/json");
			
			xmlhttp.onreadystatechange = function() {
				if(xmlhttp.readyState == 4 && xmlhttp.status == 200) {
					
					var dbug = xmlhttp.responseText;	//TODO: remove debug
					
					var st = "";
					//window.open("AppCreate.php");
				}
			}

			xmlhttp.send(toSend);
		
		}
	</script>
</head>
<body id="body">
	<label for="header">Header: </label> 
	
	<input type="text" id="header">
	
	<br>
	
	<label for="content">Content</label>
	<br>
	<textarea id="content" rows="20" cols="100"></textarea> <!-- TODO: style this for size -->
	
	<br>
	
	<br>
	
	<button onclick="save()">Gem</button>
</body>

</html>